<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机选择</title>
</head>

<body>
  随机选择你要听的歌：<input type="button" value="选择" id="btn">
  <select name="" id="food">
    <option value="">朝露人间</option>
    <option value="">多情应是我</option>
    <option value="">十年一晌</option>
    <option value="">春分十一年</option>
    <option value="">故事外的人</option>
    <option value="">生而为匠</option>
    <option value="">读秒</option>
  </select>

  <script src="js/common.js"></script>
  <script>
    var btn = my$("btn");
    var food = my$("food");
    var ops = food.getElementsByTagName("option");

    /*
      1.根据获取到的下拉框长度，生成一个 0 - 下拉框长度的随机数 
      2.将生成的随机数作为选中项，设置属性selected为true
    */
    addEvent(btn, "click", function () {
      // 随机选中 
      var n = Math.floor(Math.random() * ops.length);
      ops[n].selected = true;
    });

  </script>
</body>

</html>